home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
MDEF__
/
UTILITIE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-01-02
|
2KB
|
139 lines
#include "MacTypes.h"
#include "Quickdraw.h"
#include "WindowMgr.h"
#define ONE 65536L
#define ZOOMSTEPS 16
Fixed fract;
int blend(i1,i2)
int i1,i2;
{
Fixed smallFix,bigFix,tempFix;
smallFix = ONE * i1;
bigFix = ONE * i2;
tempFix = FixMul(fract,bigFix)+FixMul(ONE-fract,smallFix);
return(FixRound(tempFix));
}
zoomrect(smallrect,bigrect,zoomup)
Rect *smallrect,*bigrect;
Boolean zoomup;
{
Fixed factor;
Rect rect1,rect2,rect3,rect4;
GrafPtr savePort,deskPort;
int i;
GetPort(&savePort);
OpenPort(deskPort = (GrafPtr)NewPtr(sizeof(GrafPort)));
InitPort(deskPort);
SetPort(deskPort);
PenPat(gray);
PenMode(notPatXor);
if (zoomup){
rect1 = *smallrect;
factor = FixRatio(6,5);
fract = FixRatio(541,10000);
}
else{
rect1 = *bigrect;
factor = FixRatio(5,6);
fract = ONE;
}
rect2 = rect1;
rect3 = rect1;
FrameRect(&rect1);
for (i=1;i<=ZOOMSTEPS;i++){
rect4.left = blend(smallrect->left,bigrect->left);
rect4.right = blend(smallrect->right,bigrect->right);
rect4.top = blend(smallrect->top,bigrect->top);
rect4.bottom = blend(smallrect->bottom,bigrect->bottom);
FrameRect(&rect4);
FrameRect(&rect1);
rect1 = rect2;
rect2 = rect3;
rect3 = rect4;
fract = FixMul(fract,factor);
}
FrameRect(&rect1);
FrameRect(&rect2);
FrameRect(&rect3);
ClosePort(deskPort);
DisposPtr((Ptr)deskPort);
PenNormal();
SetPort(savePort);
}
ltog(r)
Rect *r;
{
Point p1,p2;
p1 = topLeft(*r);
p2 = botRight(*r);
LocalToGlobal(&p1);
LocalToGlobal(&p2);
Pt2Rect(p1,p2,r);
}
zoomport(wind,up)
WindowPtr wind;
Boolean up;
{
Rect r1,r2,r3;
SetPort(wind);
SetRect(&r1,0,20,0,20);
r3 = wind->portRect;
r2 = r3;
InsetRect(&r2,(r3.right-r3.left+20)/2,(r3.bottom-r3.top+20)/2);
ltog(&r2);
ltog(&r3);
if (up){
zoomrect(&r1,&r2,TRUE);
zoomrect(&r2,&r3,TRUE);
ShowWindow(wind);
SetPort(wind);
}
else{
HideWindow(wind);
zoomrect(&r2,&r3,FALSE);
zoomrect(&r1,&r2,FALSE);
}
}
centerwindow(wind,r)
WindowPtr wind;
Rect *r;
{
Rect r2;
int windW,windH;
int rectW,rectH;
r2 = wind->portRect;
windW = r2.right-r2.left;
windH = r2.bottom-r2.top;
rectW = r->right-r->left;
rectH = r->bottom-r->top;
MoveWindow (wind,
r->left+(rectW-windW)/2,
r->top+(rectH-windH)/2,
FALSE);
}
centerrect(r1,r2)
Rect *r1,*r2;
{
OffsetRect (r1,
((r2->right-r2->left)-(r1->right-r1->left))/2-r1->left,
((r2->bottom-r2->top)-(r1->bottom-r1->top))/2-r1->top);
}